<template>
  <!-- 容器 -->
  <div class="charts" ref="charts"></div>
</template>

<script>
// 引入echarts
import * as echarts from 'echarts'
import { mapState } from 'vuex'
export default {
  name: '',
  mounted() {
    // 初始化echarts实例
    let lineChart = echarts.init(this.$refs.charts)
    // 配置数据
    lineChart.setOption({
      xAxis: {
        show: false,
        type: 'category',
      },
      yAxis: {
        show: false,
      },
      // 系列
      series: [
        {
          type: 'line',
          smooth: true,
          data: this.listState.visitTrend,
          // 拐点样式设置
          itemStyle: {
            opacity: 0,
          },
          // 线条样式
          lineStyle: {
            color: '#ad73e3',
          },
          // 填充颜色
          areaStyle: {
            color: {
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: '#cbabe8', // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: '#fff', // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
        },
      ],
      // 布局测试
      grid: {
        left: 0,
        top: 0,
        right: 0,
        bottom: 0,
      },
    })
  },
  computed: {
    ...mapState({
      listState: (state) => state.home.list,
    }),
  },
}
</script>

<style>
.charts {
  width: 100%;
  height: 100%;
}
</style>